package com.company.zhaobank;

import java.util.Scanner;

// 新编码
public class Main1 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] numbers = new int[n];
        for(int i = 0;i < n;i++){
            numbers[i] = sc.nextInt();
        }

        String[] res = new String[n];
        for(int i = 0;i < n;i++){
            res[i] = getFinalRes(numbers[i]);
        }

        for (int i = 0; i < n ; i++) {
            System.out.println(res[i]);
        }


    }

    private static String getFinalRes(int number) {
        if(number == 0){
            return "0";
        }
        if(number > 0 && number < 10){
            return removePreZero("00000000" + getBinaryNum(number));
        }else if(number > 9 && number < 100){
            String pre = getBinaryNum(number / 10);
            String back = getBinaryNum(number % 10);
            return removePreZero("0000" + pre + back);
        }else{
            String pre = getBinaryNum(number / 100);
            String middle = getBinaryNum((number - (number / 100) * 100) / 10 );
            String back = getBinaryNum((number - (number / 100) * 100) % 10);
            return removePreZero(pre + middle + back);
        }


    }

    private static String removePreZero(String s){

        char[] chr = s.toCharArray();


        for(int i = 0,j = chr.length - 1;i < j;i++,j--){
            char t = chr[i];
            chr[i] = chr[j];
            chr[j] = t;
        }

        int i = 0;

        while (chr[i] == '0' && i < s.length()){
            i++;
        }
        if(i == s.length()){
            return "0";
        }else{
            StringBuilder sb = new StringBuilder();
            while (i < chr.length){
                sb.append(chr[i]);
                i++;
            }
            return sb.toString();
        }
    }



    private static String getBinaryNum(int n){
        if(n == 0){
            return "0000";
        }
        if(n == 1){
            return "0001";
        }
        if(n == 2){
            return "0010";
        }
        if(n == 3){
            return "0011";
        }
        if(n == 4){
            return "0100";
        }
        if(n == 5){
            return "0101";
        }
        if(n == 6){
            return "0110";
        }
        if(n == 7){
            return "0111";
        }
        if(n == 8){
            return "1000";
        }
        if(n == 9){
            return "1001";
        }
        return "0000";
    }
}
